package 静态内部类;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lenovo
 * Date: 2022-06-26
 * Time: 17:37
 */
class OuterClass{
    public int a = 10;
    static class InnerClass{
        public int a = 20;
        public int b = 20;
        public OuterClass outerClass;

        public InnerClass(OuterClass outerClass) {//接收外部对象引用
            this.outerClass = outerClass;//将外部的引用的值传给静态内部类的引用
        }

        public void fun(){
            System.out.println(a);
            System.out.println(outerClass.a);//通过引用访问
        }

    }
    public void test(){


    }
}
public class Test {
    class D{

    }
    public static void main(String[] args) {
        Test.D d = new Test().new D();
        OuterClass.InnerClass innerClass = new OuterClass.InnerClass(new OuterClass());//实例化外部对象
        innerClass.fun();
    }
}
